﻿insert into wf_dictionary(Value, subgroup, state)
values
('晋升', '请示类别', 1)
,('招聘', '请示类别', 1)
,('培训', '请示类别', 1)
,('薪酬', '请示类别', 1)
,('保险/公积金', '请示类别', 1)
,('辞退', '请示类别', 1)
, ('办公用品', '请示类别', 1)
, ('企划宣传', '请示类别', 1)
, ('来访招待', '请示类别', 1)
, ('外联', '请示类别', 1)
, ('活动', '请示类别', 1)
, ('出差', '请示类别', 1)
, ('采购', '请示类别', 1)
, ('其他', '请示类别', 1)
, ('综合管理部', '部门', 1)
, ('金融行业事业部', '部门', 1)
, ('软件开发事业部', '部门', 1)
, ('涉密集成事业部', '部门', 1)
, ('智能交通事业部', '部门', 1)
, ('现金', '出纳记入', 1)
, ('支票', '出纳记入', 1)
, ('电汇', '出纳记入', 1)
, ('其他', '出纳记入', 1);

insert into wf_dictionary(value, subgroup, state)
values('年休假','请假类别',1)
,('病假','请假类别',1)
,('事假','请假类别',1)
,('婚假','请假类别',1)
,('产假/护理假','请假类别',1)
,('丧假','请假类别',1)
,('串休','请假类别',1);

insert into wf_dictionary(value, subgroup, state)
values('是', '布尔类型', 1)
,('否', '布尔类型', 1);

insert into wf_dictionary(value, subgroup, state)
values('外出', '特殊考勤类别', 1)
,('忘记打卡', '特殊考勤类别', 1)
,('其他', '特殊考勤类别', 1);

--
-- TOC entry 2339 (class 0 OID 33453)
-- Dependencies: 192
-- Data for Name: wf_form; Type: TABLE DATA; Schema: public; Owner: postgres
--

INSERT INTO wf_form (id, name, state, version) VALUES (1, '请示审批表单', 0, 5);
INSERT INTO wf_form (id, name, state, version) VALUES (2, '用章审批表单', 0, 7);
INSERT INTO wf_form (id, name, state, version) VALUES (3, '杂费报销表单', 0, 4);
INSERT INTO wf_form (id, name, state, version) VALUES (4, '特殊考勤表单', 0, 4);
INSERT INTO wf_form (id, name, state, version) VALUES (5, '请假表单', 0, 4);
INSERT INTO wf_form (id, name, state, version) VALUES (6, '设备领用表单', 0, 1);
INSERT INTO wf_form (id, name, state, version) VALUES (7, '加班申请表单', 0, 1);

--
-- TOC entry 2431 (class 0 OID 0)
-- Dependencies: 191
-- Name: wf_form_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
--

SELECT pg_catalog.setval('wf_form_id_seq', 7, true);


INSERT INTO wf_field (id, formid, controlid, name, nullable, editable, source, state, argument, defaultvalue) VALUES (1, 1, 1, '申请主题', false, false, 0, 1, NULL, NULL);
INSERT INTO wf_field (id, formid, controlid, name, nullable, editable, source, state, argument, defaultvalue) VALUES (2, 2, 8, '呈报', true, false, 0, 1, '总经理', NULL);
INSERT INTO wf_field (id, formid, controlid, name, nullable, editable, source, state, argument, defaultvalue) VALUES (3, 2, 1, '抄报', true, false, 0, 1, NULL, NULL);
INSERT INTO wf_field (id, formid, controlid, name, nullable, editable, source, state, argument, defaultvalue) VALUES (4, 2, 5, '份数', true, false, 0, 1, '份数', NULL);
INSERT INTO wf_field (id, formid, controlid, name, nullable, editable, source, state, argument, defaultvalue) VALUES (5, 2, 5, '页/份', true, false, 0, 1, '份数', NULL);
INSERT INTO wf_field (id, formid, controlid, name, nullable, editable, source, state, argument, defaultvalue) VALUES (6, 2, 4, '申请公章', false, false, 0, 1, '布尔类型', NULL);
INSERT INTO wf_field (id, formid, controlid, name, nullable, editable, source, state, argument, defaultvalue) VALUES (7, 2, 4, '申请合同章', false, false, 0, 1, '布尔类型', NULL);
INSERT INTO wf_field (id, formid, controlid, name, nullable, editable, source, state, argument, defaultvalue) VALUES (25, 2, 4, '申请法人印章', false, false, 0, 1, '布尔类型', NULL);
INSERT INTO wf_field (id, formid, controlid, name, nullable, editable, source, state, argument, defaultvalue) VALUES (8, 2, 2, '事由', false, false, 0, 1, NULL, NULL);
INSERT INTO wf_field (id, formid, controlid, name, nullable, editable, source, state, argument, defaultvalue) VALUES (9, 1, 4, '请示类别', false, false, 0, 1, '请示类别', NULL);
INSERT INTO wf_field (id, formid, controlid, name, nullable, editable, source, state, argument, defaultvalue) VALUES (10, 1, 2, '申请内容', false, false, 0, 1, NULL, NULL);
INSERT INTO wf_field (id, formid, controlid, name, nullable, editable, source, state, argument, defaultvalue) VALUES (11, 1, 6, '预计费用', false, false, 0, 1, NULL, NULL);
INSERT INTO wf_field (id, formid, controlid, name, nullable, editable, source, state, argument, defaultvalue) VALUES (12, 1, 2, '备注', true, false, 0, 1, NULL, NULL);
INSERT INTO wf_field (id, formid, controlid, name, nullable, editable, source, state, argument, defaultvalue) VALUES (26, 1, 11, '附件', true, false, 0, 1, NULL, NULL);
INSERT INTO wf_field (id, formid, controlid, name, nullable, editable, source, state, argument, defaultvalue) VALUES (13, 4, 4, '特殊考勤类别', false, false, 0, 1, '特殊考勤类别', NULL);
INSERT INTO wf_field (id, formid, controlid, name, nullable, editable, source, state, argument, defaultvalue) VALUES (14, 4, 2, '事由', false, false, 0, 1, NULL, NULL);
INSERT INTO wf_field (id, formid, controlid, name, nullable, editable, source, state, argument, defaultvalue) VALUES (15, 4, 1, '起始时间', false, false, 0, 1, NULL, NULL);
INSERT INTO wf_field (id, formid, controlid, name, nullable, editable, source, state, argument, defaultvalue) VALUES (16, 4, 1, '终止时间', false, false, 0, 1, NULL, NULL);
INSERT INTO wf_field (id, formid, controlid, name, nullable, editable, source, state, argument, defaultvalue) VALUES (17, 5, 9, '起始时间', false, false, 0, 1, NULL, NULL);
INSERT INTO wf_field (id, formid, controlid, name, nullable, editable, source, state, argument, defaultvalue) VALUES (18, 5, 9, '终止时间', false, false, 0, 1, NULL, NULL);
INSERT INTO wf_field (id, formid, controlid, name, nullable, editable, source, state, argument, defaultvalue) VALUES (19, 5, 1, '特殊说明', true, false, 0, 1, NULL, NULL);
INSERT INTO wf_field (id, formid, controlid, name, nullable, editable, source, state, argument, defaultvalue) VALUES (20, 5, 4, '请假类型', false, false, 0, 1, '请假类别', NULL);
INSERT INTO wf_field (id, formid, controlid, name, nullable, editable, source, state, argument, defaultvalue) VALUES (21, 3, 3, '事由日期', false, false, 0, 1, NULL, NULL);
INSERT INTO wf_field (id, formid, controlid, name, nullable, editable, source, state, argument, defaultvalue) VALUES (22, 3, 2, '事由（详细填写）', false, false, 0, 1, NULL, NULL);
INSERT INTO wf_field (id, formid, controlid, name, nullable, editable, source, state, argument, defaultvalue) VALUES (23, 3, 6, '金额', false, false, 0, 1, NULL, NULL);
INSERT INTO wf_field (id, formid, controlid, name, nullable, editable, source, state, argument, defaultvalue) VALUES (24, 3, 2, '备注', true, false, 0, 1, NULL, NULL);

INSERT INTO wf_field (id, formid, controlid, name, nullable, editable, source, state, argument, defaultvalue) VALUES (27, 7, 1, '开发组名', true, false, 0, 1, NULL, NULL);
INSERT INTO wf_field (id, formid, controlid, name, nullable, editable, source, state, argument, defaultvalue) VALUES (28, 7, 3, '加班日期', false, false, 0, 1, NULL, NULL);
INSERT INTO wf_field (id, formid, controlid, name, nullable, editable, source, state, argument, defaultvalue) VALUES (29, 7, 1, '加班人员', false, false, 0, 1, NULL, NULL);
INSERT INTO wf_field (id, formid, controlid, name, nullable, editable, source, state, argument, defaultvalue) VALUES (30, 7, 2, '加班内容', false, false, 0, 1, NULL, NULL);
INSERT INTO wf_field (id, formid, controlid, name, nullable, editable, source, state, argument, defaultvalue) VALUES (31, 7, 1, '预期目标', false, false, 0, 1, NULL, NULL);
INSERT INTO wf_field (id, formid, controlid, name, nullable, editable, source, state, argument, defaultvalue) VALUES (32, 7, 1, '实际成果', false, false, 0, 1, NULL, NULL);
INSERT INTO wf_field (id, formid, controlid, name, nullable, editable, source, state, argument, defaultvalue) VALUES (33, 7, 1, '实际加班起始时间', false, false, 0, 1, NULL, NULL);
INSERT INTO wf_field (id, formid, controlid, name, nullable, editable, source, state, argument, defaultvalue) VALUES (34, 7, 1, '实际加班结束时间', false, false, 0, 1, NULL, NULL);
INSERT INTO wf_field (id, formid, controlid, name, nullable, editable, source, state, argument, defaultvalue) VALUES (35, 7, 1, '休息起止', true, false, 0, 1, NULL, NULL);
INSERT INTO wf_field (id, formid, controlid, name, nullable, editable, source, state, argument, defaultvalue) VALUES (36, 7, 5, '实际小时数', false, false, 0, 1, NULL, NULL);

INSERT INTO wf_field (id, formid, controlid, name, nullable, editable, source, state, argument, defaultvalue) VALUES (37, 6, 2, '申请理由及用途', false, false, 0, 1, NULL, NULL);
INSERT INTO wf_field (id, formid, controlid, name, nullable, editable, source, state, argument, defaultvalue) VALUES (38, 6, 2, '设备名称及规格编号', false, false, 0, 1, NULL, NULL);
INSERT INTO wf_field (id, formid, controlid, name, nullable, editable, source, state, argument, defaultvalue) VALUES (39, 6, 2, '外设设备', true, false, 0, 1, NULL, NULL);
INSERT INTO wf_field (id, formid, controlid, name, nullable, editable, source, state, argument, defaultvalue) VALUES (40, 6, 1, '使用时间', true, false, 0, 1, NULL, NULL);
INSERT INTO wf_field (id, formid, controlid, name, nullable, editable, source, state, argument, defaultvalue) VALUES (41, 6, 1, '存放地点', true, false, 0, 1, NULL, NULL);



--
-- TOC entry 2427 (class 0 OID 0)
-- Dependencies: 193
-- Name: wf_field_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
--

SELECT pg_catalog.setval('wf_field_id_seq', 41, true);

-- 添加基础角色
insert into sys_Role(name) values('员工'),('中层管理'),('部门主管/副总');

-- 添加部门
insert into sys_Org(name) values('综合管理部'),('金融行业事业部'),('软件开发事业部'),('涉密集成事业部'),('智能交通事业部'),('财务部');

-- 添加职位
insert into sys_Position(id, name) values
(1,	'总经理'),
(2,	'副董事长'),
(3,	'会计'),
(4,	'出纳'),
(5,	'商务部经理'),
(6,	'商务专员'),
(7,	'综合管理部经理'),
(8,	'人事行政专员'),
(9,	'美工'),
(10,'网络管理员'),
(11,'行政前台'),
(12,'副总经理'),
(13,'产品事业部渠道经理'),
(14,'高级客户经理'),
(15,'行政专员'),
(16,'产品售后副经理'),
(17,'行业客户经理'),
(18,'市场部经理'),
(19,'产品开发部经理'),
(20,'高级软件工程师'),
(21, '董事长');


SELECT pg_catalog.setval('sys_position_id_seq', 20, true);

-- 添加用户
insert into sys_User(id, loginname, password, salt) values
(2	, 'wangjue', md5('wangjue'||'wangjue'||'xinkai'), 'xinkai'),
(3	, 'zhengjianghong', md5('zhengjianghong'||'zhengjianghong'||'xinkai'), 'xinkai'),
(4	, 'donglinlin', md5('donglinlin'||'donglinlin'||'xinkai'), 'xinkai'),
(5	, 'liyi', md5('liyi'||'liyi'||'xinkai'), 'xinkai'),
(6	, 'tanhuimin', md5('tanhuimin'||'tanhuimin'||'xinkai'), 'xinkai'),
(7	, 'gaocong', md5('gaocong'||'gaocong'||'xinkai'), 'xinkai'),
(8	, 'caoying', md5('caoying'||'caoying'||'xinkai'), 'xinkai'),
(9	, 'liujing', md5('liujing'||'liujing'||'xinkai'), 'xinkai'),
(10	, 'duanshuangshuang', md5('duanshuangshuang'||'duanshuangshuang'||'xinkai'), 'xinkai'),
(11	, 'wanghaiyang', md5('wanghaiyang'||'wanghaiyang'||'xinkai'), 'xinkai'),
(12	, 'luoxiaoqing', md5('luoxiaoqing'||'luoxiaoqing'||'xinkai'), 'xinkai'),
(13	, 'liuhaijun', md5('liuhaijun'||'liuhaijun'||'xinkai'), 'xinkai'),
(14	, 'guoshibin', md5('guoshibin'||'guoshibin'||'xinkai'), 'xinkai'),
(15	, 'chenzhao', md5('chenzhao'||'chenzhao'||'xinkai'), 'xinkai'),
(16	, 'xiejinyong', md5('xiejinyong'||'xiejinyong'||'xinkai'), 'xinkai'),
(17	, 'zhougang', md5('zhougang'||'zhougang'||'xinkai'), 'xinkai'),
(18	, 'yangqian', md5('yangqian'||'yangqian'||'xinkai'), 'xinkai'),
(19	, 'zhouxi', md5('zhouxi'||'zhouxi'||'xinkai'), 'xinkai'),
(20	, 'liangbaofeng', md5('liangbaofeng'||'liangbaofeng'||'xinkai'), 'xinkai'),
(21	, 'liuhaipeng', md5('liuhaipeng'||'liuhaipeng'||'xinkai'), 'xinkai'),
(22	, 'mujianhua', md5('mujianhua'||'mujianhua'||'xinkai'), 'xinkai'),
(23	, 'zhangqing', md5('zhangqing'||'zhangqing'||'xinkai'), 'xinkai'),
(24	, 'zhanjinxin', md5('zhanjinxin'||'zhanjinxin'||'xinkai'), 'xinkai'),
(25	, 'yinjinke', md5('yinjinke'||'yinjinke'||'xinkai'), 'xinkai'),
(26	, 'yangshengjun', md5('yangshengjun'||'yangshengjun'||'xinkai'), 'xinkai'),
(27	, 'guanyunke', md5('guanyunke'||'guanyunke'||'xinkai'), 'xinkai');

SELECT pg_catalog.setval('sys_user_id_seq', 25, true);

insert into sys_UserInfo(userid, username, sex, workemail, mobile, idcard, tel) values
(2	, '王珏', '男', 'wangjue@xk-soft.com', '0', '0', '0'),
(3	, '郑江红', '男', 'zjh@xinkaidigital.com', '0', '0', '0'),
(4	, '董琳林', '男', 'donglinlin@xk-soft.com', '0', '0', '0'), -- 王珏
(5	, '李轶', '男', 'liyi@xk-soft.com', '0', '0', '0'),  -- 王珏
(6	, '谭慧敏', '男', 'tanhuimin@xk-soft.com', '0', '0', '0'), -- 王珏
(7	, '高聪', '男', 'gaocong@xk-soft.com', '0', '0', '0'), -- 谭慧敏
(8	, '曹莹', '男', 'caoying@xk-soft.com', '0', '0', '0'), -- 王珏
(9	, '刘晶', '男', 'liujing@xk-soft.com', '0', '0', '0'), -- 曹莹
(10	, '段双双', '男', 'duanshuangshuang@xk-soft.com', '0', '0', '0'), -- 曹莹
(11	, '王海洋', '男', 'wanghaiyang@xk-soft.com', '0', '0', '0'), -- 曹莹
(12	, '骆晓清', '男', 'luoxiaoqing@xk-soft.com', '0', '0', '0'), -- 曹莹
(13	, '刘海君', '男', 'liuhaijun@xk-soft.com', '0', '0', '0'),-- 王珏
(14	, '郭世彬', '男', 'guoshibin@xk-soft.com', '0', '0', '0'), -- 刘海君
(15	, '陈朝', '男', 'chenzhao@xk-soft.com', '0', '0', '0'), -- 刘海君
(16	, '谢晋勇', '男', 'xiejinyong@xk-soft.com', '0', '0', '0'), -- 刘海君
(17	, '周罡', '男', 'zhougang@xk-soft.com', '0', '0', '0'), -- 刘海君
(18	, '杨谦', '男', 'yangqian@xk-soft.com', '0', '0', '0'), -- 刘海君
(19	, '周希', '男', 'zhouxi@xk-soft.com', '0', '0', '0'), -- 刘海君
(20	, '梁宝峰', '男', 'liangbaofeng@xk-soft.com', '0', '0', '0'), -- 刘海君
(21	, '刘海鹏', '男', 'liuhaipeng@xk-soft.com', '0', '0', '0'), -- 刘海君
(22	, '牟建华', '男', 'mujianhua@xk-soft.com', '0', '0', '0'), -- 刘海君
(23	, '张青', '男', 'zhangqing@xk-soft.com', '0', '0', '0'), -- 牟建华
(24	, '战金鑫', '男', 'zhanjinxin@xk-soft.com', '0', '0', '0'), -- 牟建华
(25	, '尹进科', '男', 'yinjinke@xk-soft.com', '0', '0', '0'), -- 牟建华
(26,  '杨胜军', '男', 'yangshengjun@xk-soft.com', '0','0','0'),
(27,  '关运科', '男', 'gyk@xinkaidigital.com', '0','0','0');
-- 董事长 关运科 gyk@xinkaidigital.com

insert into sys_UserOrgPosition	select 2, (select id from sys_position where name = '总经理' limit 1), 1, (select userid from sys_UserInfo where username = '' limit 1) t2	;
insert into sys_UserOrgPosition	select 3, (select id from sys_position where name = '副董事长' limit 1), 1, (select userid from sys_UserInfo where username = '' limit 1) t2	;
insert into sys_UserOrgPosition	select 4, (select id from sys_position where name = '会计' limit 1), 1, (select userid from sys_UserInfo where username = '王珏' limit 1) t2	;
insert into sys_UserOrgPosition	select 5, (select id from sys_position where name = '出纳' limit 1), 1, (select userid from sys_UserInfo where username = '王珏' limit 1) t2	;
insert into sys_UserOrgPosition	select 6, (select id from sys_position where name = '商务部经理' limit 1), 1, (select userid from sys_UserInfo where username = '王珏' limit 1) t2	;
insert into sys_UserOrgPosition	select 7, (select id from sys_position where name = '商务专员' limit 1), 1, (select userid from sys_UserInfo where username = '谭慧敏' limit 1) t2	;
insert into sys_UserOrgPosition	select 8, (select id from sys_position where name = '综合管理部经理' limit 1), 1, (select userid from sys_UserInfo where username = '王珏' limit 1) t2	;
insert into sys_UserOrgPosition	select 9, (select id from sys_position where name = '人事行政专员' limit 1), 1, (select userid from sys_UserInfo where username = '曹莹' limit 1) t2	;
insert into sys_UserOrgPosition	select 10, (select id from sys_position where name = '美工' limit 1), 1, (select userid from sys_UserInfo where username = '曹莹' limit 1) t2	;
insert into sys_UserOrgPosition	select 11, (select id from sys_position where name = '网络管理员' limit 1), 1, (select userid from sys_UserInfo where username = '曹莹' limit 1) t2	;
insert into sys_UserOrgPosition	select 12, (select id from sys_position where name = '行政前台' limit 1), 1, (select userid from sys_UserInfo where username = '曹莹' limit 1) t2	;


insert into sys_UserOrgPosition	select 13, (select id from sys_position where name = '副总经理' limit 1), 2, (select userid from sys_UserInfo where username = '王珏' limit 1) t2	;
insert into sys_UserOrgPosition	select 14, (select id from sys_position where name = '产品事业部渠道经理' limit 1), 2, (select userid from sys_UserInfo where username = '刘海君' limit 1) t2	;
insert into sys_UserOrgPosition	select 15, (select id from sys_position where name = '高级客户经理' limit 1), 2, (select userid from sys_UserInfo where username = '刘海君' limit 1) t2	;
insert into sys_UserOrgPosition	select 16, (select id from sys_position where name = '高级客户经理' limit 1), 2, (select userid from sys_UserInfo where username = '刘海君' limit 1) t2	;
insert into sys_UserOrgPosition	select 17, (select id from sys_position where name = '高级客户经理' limit 1), 2, (select userid from sys_UserInfo where username = '刘海君' limit 1) t2	;
insert into sys_UserOrgPosition	select 18, (select id from sys_position where name = '高级客户经理' limit 1), 2, (select userid from sys_UserInfo where username = '刘海君' limit 1) t2	;
insert into sys_UserOrgPosition	select 19, (select id from sys_position where name = '行政专员' limit 1), 2, (select userid from sys_UserInfo where username = '刘海君' limit 1) t2	;
insert into sys_UserOrgPosition	select 20, (select id from sys_position where name = '产品售后副经理' limit 1), 2, (select userid from sys_UserInfo where username = '刘海君' limit 1) t2	;
insert into sys_UserOrgPosition	select 21, (select id from sys_position where name = '行业客户经理' limit 1), 2, (select userid from sys_UserInfo where username = '刘海君' limit 1) t2	;
insert into sys_UserOrgPosition	select 22, (select id from sys_position where name = '市场部经理' limit 1), 2, (select userid from sys_UserInfo where username = '刘海君' limit 1) t2	;
insert into sys_UserOrgPosition	select 23, (select id from sys_position where name = '产品开发部经理' limit 1), 2, (select userid from sys_UserInfo where username = '牟建华' limit 1) t2	;
insert into sys_UserOrgPosition	select 24, (select id from sys_position where name = '高级软件工程师' limit 1), 2, (select userid from sys_UserInfo where username = '牟建华' limit 1) t2	;
insert into sys_UserOrgPosition	select 25, (select id from sys_position where name = '高级软件工程师' limit 1), 2, (select userid from sys_UserInfo where username = '牟建华' limit 1) t2	;


insert into sys_userrole values
(4,	5),
(5,	5),
(6,	5),
(7,	4),
(8,	6),
(9,	4),
(10,	4),
(11,	4),
(12,	4),
(13,	6),
(14,	5),
(15,	5),
(16,	5),
(17,	5),
(18,	5),
(19,	5),
(20,	5),
(21,	5),
(22,	5),
(23,	4),
(24,	4),
(25,	4);


create or replace function create_flow(_formid int, _name text, _description text)
returns void
as
$$
declare
   _id int;
begin
insert into wf_FormInstance(TemplateFormId, Name, State, Version) 
   select Id, Name, State, Version from wf_Form where Id = $1 returning Id into _id;
insert into wf_FieldInstance(TemplateFieldId, FormId, ControlId, Name, Nullable, Editable, Source, State, Argument, DefaultValue)
  select Id, _id, ControlId, Name, Nullable, Editable, Source, State, Argument, DefaultValue from wf_Field where FormId = $1;
INSERT INTO wf_flow (formid, name, description, state) VALUES (_id, $2, $3, 1);
end;
$$
language plpgsql;

select create_flow(5, '请假单(员工)', '备注:<br/>具体年假执行标准参照《公司请休假管理规定》相应条款');
select create_flow(5, '请假单', '备注:<br/>具体年假执行标准参照《公司请休假管理规定》相应条款');
select create_flow(1, '请示审批单(员工)', NULL);
select create_flow(1, '请示审批单', NULL);
select create_flow(3, '杂费报销单', NULL);
select create_flow(2, '用章审批表(员工)', NULL);
select create_flow(2, '用章审批表', NULL);
select create_flow(4, '特殊考勤记录单', NULL);
select create_flow(6, '设备领用表(员工)', NULL);
select create_flow(6, '设备领用表', NULL);
select create_flow(7, '加班审批单', NULL);
